if( SERVER ) then

	AddCSLuaFile( "shared.lua" );

end

if( CLIENT ) then

	SWEP.PrintName = "Keys";
	SWEP.Slot = 5;
	SWEP.SlotPos = 1;
	SWEP.DrawAmmo = false;
	SWEP.DrawCrosshair = true;

end

// Variables that are used on both client and server

SWEP.Author			= "Mr Fix It, ceribik"
SWEP.Instructions	= "Left click to lock doors, Right click to unlock doors (you have to be really close)"
SWEP.Contact		= ""
SWEP.Purpose		= ""

SWEP.ViewModelFOV	= 62
SWEP.ViewModelFlip	= false
SWEP.ViewModel = Model( "" )
SWEP.WorldModel = Model( "" )
SWEP.AnimPrefix		= "rpg"

SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true

SWEP.Sound = Sound( "doors/door_latch3.wav" );

SWEP.Primary.ClipSize		= -1					// Size of a clip
SWEP.Primary.DefaultClip	= 0				// Default number of bullets in a clip
SWEP.Primary.Automatic		= false				// Automatic/Semi Auto
SWEP.Primary.Ammo			= ""

SWEP.Secondary.ClipSize		= -1				// Size of a clip
SWEP.Secondary.DefaultClip	= 0				// Default number of bullets in a clip
SWEP.Secondary.Automatic	= false				// Automatic/Semi Auto
SWEP.Secondary.Ammo			= ""



/*---------------------------------------------------------
   Name: SWEP:Initialize( )
   Desc: Called when the weapon is first loaded
---------------------------------------------------------*/
function SWEP:Initialize()

	if( SERVER ) then
	
		self:SetWeaponHoldType( "pistol" );
	
	end

end


/*---------------------------------------------------------
   Name: SWEP:Precache( )
   Desc: Use this function to precache stuff
---------------------------------------------------------*/
function SWEP:Precache()
end


/*---------------------------------------------------------
   Name: SWEP:PrimaryAttack( )
   Desc: +attack1 has been pressed
---------------------------------------------------------*/
function SWEP:PrimaryAttack()

	if( CLIENT ) then return; end

	local trace = self.Owner:GetEyeTrace();

	if( not trace.Entity:IsValid() ) then
		return;
	end
	if(!trace.Entity:IsDoor()) then
		return
	end
	if(trace.StartPos:Distance(trace.HitPos) >60) then return end
	if(player.GetByID(trace.Entity:GetNWInt("OwnerID")):IsPlayer() && trace.Entity:GetNWInt("OwnerID")==self.Owner:EntIndex()) then
		trace.Entity:Fire( "lock", "", 0 );
		
		self.Owner:EmitSound( self.Sound );
		self.Weapon:SetNextPrimaryFire( CurTime() + 1.0 );
	end

end
 
/*---------------------------------------------------------
SecondaryAttack
---------------------------------------------------------*/
function SWEP:SecondaryAttack()

	if( CLIENT ) then return; end

	local trace = self.Owner:GetEyeTrace();

	if( not trace.Entity:IsValid()) then
		return;
	end
	if(!trace.Entity:IsDoor()) then
		return
	end
	if(trace.StartPos:Distance(trace.HitPos) >60) then return end
	if(player.GetByID(trace.Entity:GetNWInt("OwnerID")):IsPlayer() && trace.Entity:GetNWInt("OwnerID")==self.Owner:EntIndex()) then
		trace.Entity:Fire( "unlock", "", 0 );
		
		self.Owner:EmitSound( self.Sound );
		self.Weapon:SetNextPrimaryFire( CurTime() + 1.0 );
	end
	
end
